package com.ynny.jdbc03.dao;

import com.ynny.jdbc03.base.BaseDAO;
import com.ynny.jdbc03.entity.Book;

import java.util.List;

public class BookDao extends BaseDAO<Book> {

    //增删改查
    //查询
    public List<Book> selectAllBooks(){


        String sql = "select * from book";
        List<Book> books = super.selectAll(sql);

        return books;


    }
    public Book selectBookById(Integer id){
        String sql = "select * from book where id = ?";
        Book book = super.selectOne(sql, id);
        return book;
    }

    public int insertBook(Book book){
        String sql = "insert into book(name,price) values(?,?)";
        int i = super.insert(sql, book.getName(),book.getPrice());
        return i;
    }


    public int updateBook(Book book){
        String sql = "update book set name= ? where id = ?";
        int i = super.update(sql, book.getName(), book.getId());
        return i;
    }

    public int deleteBook(Integer id){
        String sql = "delete from book where id = ?";
        int i = super.deleteById(sql, id);
        return i;
    }


}
